package elven.d.web.event.listener;

import org.springframework.context.ApplicationEvent;
import org.springframework.context.event.SmartApplicationListener;

import elven.d.common.log.LogFactory;
import elven.d.web.event.hello.ContentEvent;

/**
 * 李四监听器，实现有序的SmartApplicationListener
 * @author liuyongyuan
 */
public class LisiListener implements SmartApplicationListener {

	@Override
	public void onApplicationEvent(ApplicationEvent event) {
		LogFactory.d().info("李四在王五张三收到前，收到新的内容："+event.getSource());
	}

	/* 排序
	 * @see org.springframework.core.Ordered#getOrder()
	 */
	@Override
	public int getOrder() {
		return 1;
	}

	/* 判断事件类型是不是ContentEvent.class
	 * @see org.springframework.context.event.SmartApplicationListener#supportsEventType(java.lang.Class)
	 */
	@Override
	public boolean supportsEventType(Class<? extends ApplicationEvent> eventType) {
		return eventType == ContentEvent.class;
	}

	/* 判断ContentEvent的内容是不是String
	 * @see org.springframework.context.event.SmartApplicationListener#supportsSourceType(java.lang.Class)
	 */
	@Override
	public boolean supportsSourceType(Class<?> sourceType) {
		return sourceType == String.class;
	}

}
